package com.zff.rental.common;

/**
 * 接口返回的错误码和消息
 *
 * @author HCY
 */
public enum ResultCode {
    SUCCESS(0, "Success"),
    FAIL(1, "Fail"),
    USER_NOT_ADMIN(2, "不是系统管理员"),
    RECORD_NOT_EXISTS(3, "记录不存在"),
    CUSTOM_ERROR(4, ""),
    AUTHORIZATION_EXCEPTION(401, "越权操作"),
    EXCEPTION_BAD(400, "错误的请求参数"),
    EXCEPTION_NOT_FOUND(404, "找不到请求路径！"),
    EXCEPTION_DATA_ACCESS(500, "数据库异常"),
    EXCEPTION_CONNECTION_ERROR(550, "网络连接请求失败！"),
    EXCEPTION_NOT_ALLOWED(405, "不合法的请求方式"),

    IN_PARAMETERS_ERROR(100, "错误的请求参数"),

    PARAMETER_CANNOT_EMPTY(101, "必传参数不能为空！"),
    NO_PERMISSION(104, "无权限"),
    REPEAT_RECORD(116, "重复记录"),

    ACCOUNT_USER_NOT_EXIST(1001, "用户不存在"),
    ACCOUNT_USER_IS_EXIST(1002, "用户已经存在"),
    ACCOUNT_USERNAME_IS_EMPTY(1003, "用户名不能为空"),
    ACCOUNT_PASSWORD_IS_EMPTY(1004, "密码不能为空"),
    ACCOUNT_OLD_PASSWORD_IS_EMPTY(1005, "原密码不能为空"),
    ACCOUNT_NEW_PASSWORD_IS_EMPTY(1006, "新密码不能为空"),
    ACCOUNT_INVALID_PASSWORD(1007, "密码错误"),
    USER_RECORD_NOT_EXISTS(1008, "用户不存在"),
    USER_ALREADY_EXISTS(1009, "已经存在用户"),
    /***
     * 授权相关错误
     */
    TOKEN_CANNOT_EMPTY(2001, "Token不能为空"),
    TOKEN_SIGN_ERROR_OR_EXPIRY(2002, "登录授权过期，请重新授权登录"),
    UNAUTHORIZED_OPERATION(2003, "越权操作"),

    NOT_MATCH(107, "用户名和密码不匹配"),
    FAIL_GET_DATA(108, "获取信息失败"),
    BAD_REQUEST_TYPE(109, "错误的请求类型"),

    INVALID_MOBILE(110, "无效的手机号码"),
    INVALID_EMAIL(111, "无效的邮箱"),
    INVALID_GENDER(112, "无效的性别"),
    REPEAT_MOBILE(114, "已存在此手机号"),
    REPEAT_EMAIL(115, "已存在此邮箱地址"),

    LOGIN_SUCCESS(117, "登陆成功"),
    LOGOUT_SUCCESS(118, "已退出登录"),

    SEND_EMAIL_SUCCESS(119, "邮件已发送，请注意查收"),
    EDITPWD_SUCCESS(120, "修改密码成功"),
    NO_FILE_SELECT(121, "未选择文件"),
    FILE_UPLOAD_SUCCESS(122, "上传成功"),
    NO_LOGIN(123, "未登陆"),
    ILLEGAL_ARGUMENT(124, "参数不合法"),
    ERROR_CODE(125, "验证码不正确"),

    JOIN_GROUP_NOT_EXIST(125, "没有此群"),


    UNKNOWN(999, "UNKNOWN ERROR"),

    APARTMENT_HAS_ROOM(1001, "公寓下有房间，请先删除公寓下的房间" );


    private final int code;
    private final String msg;

    ResultCode(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public int value() {
        return code;
    }

    public int getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public BusinessException toException() {
        return new BusinessException(this);
    }
}
